import { createRouter,createWebHashHistory } from "vue-router";

const routes = [
    
    {
        path:"/manage",component:()=>import("../views/manage/main.vue"),
        name:"manage_main",meta:{title:'管理主页'},
        children:[
            {
                path:'/manage/:type',
                component:()=>import("../views/manage/list.vue")
            },
            {
                path:'/manage/:type/modify/:id',
                component:()=>import("../views/manage/modify.vue")
            }
            // {
            //     path:'/manage/activity',
            //     name:"manage_activity",meta:{title:'活动管理'},
            //     component:()=>import('../views/manage/activity/list.vue')
            // },
           
            //  {
            //     path:'/manage/activity/modify',
            //     name:"manage_activity_modify",meta:{title:'活动管理修改'},
            //     component:()=>import('../views/manage/activity/modify.vue')
            // },
            // {
            //     path:'/manage/client',
            //     name:"manage_client",meta:{title:'用户管理'},
            //     component:()=>import('../views/manage/client/list.vue')
            // },
            //  {
            //     path:'/manage/client/modify',
            //     name:"manage_client_modify",meta:{title:'用户管理修改'},
            //     component:()=>import('../views/manage/client/modify.vue')
            // },
            //  {
            //     path:'/manage/enroll',
            //     name:"manage_enroll",meta:{title:'报名管理'},
            //     component:()=>import('../views/manage/enroll/list.vue')
            // },
            //  {
            //     path:'/manage/enroll/modify',
            //     name:"manage_enroll_modify",meta:{title:'报名管理修改'},
            //     component:()=>import('../views/manage/enroll/modify.vue')
            // },
            //   {
            //     path:'/manage/ticket',
            //     name:"manage_ticket",meta:{title:'购票管理'},
            //     component:()=>import('../views/manage/ticket/list.vue')
            // },
            //  {
            //     path:'/manage/ticket/modify',
            //     name:"manage_ticket_modify",meta:{title:'购票管理修改'},
            //     component:()=>import('../views/manage/ticket/modify.vue')
            // },
            //   {
            //     path:'/manage/member',
            //     name:"manage_member",meta:{title:'成员管理'},
            //     component:()=>import('../views/manage/member/list.vue')
            // },
            //  {
            //     path:'/manage/member/modify',
            //     name:"manage_member_modify",meta:{title:'成员管理修改'},
            //     component:()=>import('../views/manage/member/modify.vue')
            // },
            //   {
            //     path:'/manage/signIn',
            //     name:"manage_signIn",meta:{title:'签到管理'},
            //     component:()=>import('../views/manage/signIn/list.vue')
            // },
            //  {
            //     path:'/manage/signIn/modify',
            //     name:"manage_signIn_modify",meta:{title:'签到管理修改'},
            //     component:()=>import('../views/manage/signIn/modify.vue')
            // },
        ]
    },
    {
        path:'/',component:()=>import("../App.vue"),
        children:[
        {
            path:"/index",
            name:"index",meta:{title:'主页'},
            component:()=>import("../views/home.vue")
        },
        {
            path:"/login",
            name:"Login",
            meta:{
                title:"登陆"
            },
            component:()=> import("../views/client/login.vue")
        },
        {
            path:"/register",
            name:"Register",
            meta:{
                title:"注册"
            },
            component:()=> import("../views/client/register.vue")
        },
        ]
    },
    {path:'/404notFound',name:'404NotFound',component:()=>import("../views/errors/404NotFound.vue"),
    meta: {title:'未找到'}},

    // {path:'/:pathMatch(.*)',redirect: "/404notFound"}
]

const router = createRouter({
    history:createWebHashHistory("/"),
    routes
})
// 分普通用户和管理员的身份
router.beforeEach((to,from,next)=>{
    const c_token = sessionStorage.getItem("Autorization")
    // const authority = localStorage.getItem("authority")
    console.log(to,from,c_token)
    // const role = to.meta.authority
    // if(to.path === ''){
    // next(from.path)
    // }else if(to.matched.length === 0){
    //     // console.log(1)
    //     next('/404notFound')
    // } else if(to.path === '/register'|| to.path == '/404notFound'){
    //     next()
    // } else if (!c_token && to.path !== '/login') {
    //     // console.log(2)
    //     next('/login');
    // } else {
        // console.log(3)
    //     // next('/manage');
        next()
    // }
    // next()
})

export default router